package com.dykj.fireFighting.web.base.app;

import com.dykj.fireFighting.api.base.enterprise.entity.Enterprise;
import com.dykj.fireFighting.api.base.enterprise.service.IEnterpriseService;
import com.dykj.fireFighting.api.base.news.dto.RealTimeInfoDto;
import com.dykj.fireFighting.api.base.news.entity.RealTimeInfo;
import com.dykj.fireFighting.api.base.news.service.IRealTimeInfoService;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.vo.LoginUserVo;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: zly
 * @Description : app消防资讯
 * @Date: 2021-10-20
 */
@Slf4j
@Api(value = "消防资讯接口", tags = {"消防资讯接口"})
@RestController
@RequestMapping("app/realTimeInfo")
public class AppRealTimeInfoController {

    @DubboReference
    private IRealTimeInfoService realTimeInfoService;
    @DubboReference
    private IEnterpriseService enterpriseService;

    /**
     * 消防资讯列表
     *
     * @return
     */
    @AutoLog(value = "消防资讯-分页列表查询")
    @ApiOperation(value = "消防资讯分页列表", notes = "消防资讯分页列表")
    @GetMapping("/list")
    public CommonResult<PageVo<RealTimeInfo>> treeGrid(RealTimeInfoDto realTimeInfoDto) {
        LoginUserVo user = ShiroUtil.getUser();
        //单位类型(社会单位:0，维保单位:1，监控中心:2)
        Integer enterpriseType = user.getEnterpriseType();
        if(2 == enterpriseType){
            realTimeInfoDto.setUnitId(user.getEnterpriseId().toString());
        }
        if(0 == enterpriseType){
            Enterprise centerEnter = enterpriseService.getInfoByBindingCode(user.getBindingCode());
            realTimeInfoDto.setUnitId(centerEnter.getId().toString());
        }
        PageVo<RealTimeInfo> page = realTimeInfoService.pageList(realTimeInfoDto);
        return CommonResult.success(page);
    }
}
